<?php

namespace App\Http\Controllers;

use EasyWeChat\Foundation\Application;
use Illuminate\Http\Request;

class MaterialController extends Controller
{
    //素材管理
    public $material;

    //消息群发
    public $broadcast;

    /**
     * 依赖注入
     * MaterialController constructor.
     * @param Application $app
     */
    public function __construct(Application $app)
    {
        $this->material = $app->material;
        $this->broadcast = $app->broadcast;
    }

    /**
     * 上传图片
     * @return \EasyWeChat\Support\Collection
     */
    public function image()
    {
        $image = $this->material->uploadImage(public_path().'/images/hedy.jpg');
        return $image;
    }

    /**
     * 上传音频文件
     * @return \EasyWeChat\Support\Collection
     */
    public function audio()
    {
        $audio = $this->material->uploadVoice(public_path().'/images/音频文件名');
        return $audio;
    }

    /**
     * 获取所有的图片
     * @return array
     */
    public function materials()
    {
        $images = $this->material->lists('news');//获取图文消息，这个是类型
        return $images;
    }

    /**
     * 拿到内容
     * @param $mediaId
     * @return mixed
     */
    public function media($mediaId)
    {
        $media = $this->material->get($mediaId);
        return $media;
    }

    /**
     * 消息群发
     * @return string
     */
    public function message()
    {
        $this->broadcast->send('news','media_id',[
            //发送图文消息到两个用户中
            'openId_one',
            'openId_two'
        ]);
        //随便返回一个字符串，看代码是否执行到
        return 'Hedy';
    }

    /**
     * 获取别名
     * @return string
     */
    public function text()
    {
        $this->broadcast->sendText('Hedy',[
            //发送到两个用户中
            'openId_one',
            'openId_two'
        ]);
        return 'send success';
    }
}
